/*
 *	This file is part of Lounge-Cast.
 *
 *  Author:  	Markus Moormann
 *	E-mail:  	mmoorman@uni-osnabrueck.de
 *	Copyright:	University of Osnabrueck (Zentrum Virtuos)
 * 	Website:	www.uni-osnabrueck.de
 *	Date:		16.02.2011
 *
 *	Lounge-Cast is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *	Lounge-Cast is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Lounge-Cast.  If not, see <http://www.gnu.org/licenses/>.
 */
package multimedia.control
{
	import com.adobe.cairngorm.control.FrontController;
	
	import multimedia.control.command.author.*;
	import multimedia.control.command.category.GetCategoriesCommand;
	import multimedia.control.command.contact.*;
	import multimedia.control.command.feed.*;
	import multimedia.control.command.login.*;
	import multimedia.control.command.media.*;
	import multimedia.control.command.player.*;
	import multimedia.control.command.playlist.*;
	import multimedia.control.command.preview.*;
	import multimedia.control.command.properties.*;
	import multimedia.control.command.user.*;
	import multimedia.control.command.validation.*;
	import multimedia.control.event.author.*;
	import multimedia.control.event.category.GetCategoriesEvent;
	import multimedia.control.event.contact.*;
	import multimedia.control.event.feed.*;
	import multimedia.control.event.login.*;
	import multimedia.control.event.media.*;
	import multimedia.control.event.player.*;
	import multimedia.control.event.playlist.*;
	import multimedia.control.event.preview.*;
	import multimedia.control.event.properties.*;
	import multimedia.control.event.user.*;
	import multimedia.control.event.validation.*;


	/**
	 * FrontController get informed if an event is dispatched and executes
	 * the adequate Command
	 */
	public class Controller extends FrontController
	{
		/**
		 * constructor 
		 */
		public function Controller()
		{
			super();
			addValidationCommands();
			addPropertiesCommands();
			addUserCommands();
			addFeedCommands();
			addPlayerCommands();
			addPlaylistCommands();
			addMediaCommands();
			addLoginCommands();
			addPreviewCommands();
			addAuthorCommands();
			addContactCommands();
			addCategoryCommands();
		}
		
		/**
		 * add all commands for categories
		 */
		private function addCategoryCommands():void
		{
			addCommand(GetCategoriesEvent.GET, GetCategoriesCommand);
		}
		
		/**
		 * add all commands for contact
		 */
		private function addContactCommands():void
		{
			addCommand(SendMailToUserEvent.SEND, SendMailToUserCommand);
		}
		
		/**
		 * add all author commands
		 */
		private function addAuthorCommands():void
		{
			addCommand(CloseAuthorPanelEvent.CLOSE, CloseAuthorPanelCommand);
		}
		
		/**
		 * add all preview commands
		 */
		private function addPreviewCommands():void
		{
			addCommand(ChangeStateEvent.CHANGE, ChangeStateCommand);
			addCommand(LoadDFXPXMLEvent.LOAD, LoadDFXPXMLCommand);
			addCommand(LoadVideoEvent.LOAD, LoadVideoCommand);
			addCommand(LoadViewerXMLEvent.LOAD, LoadViewerXMLCommand);
			addCommand(LoadSlideEvent.LOAD, LoadSlideCommand);
			addCommand(LoadTextEvent.LOAD, LoadTextCommand);
			addCommand(LoadImageEvent.LOAD, LoadImageCommand);
		}
		
		/**
		 * add all validation commands
		 */
		private function addValidationCommands():void
		{
			addCommand(SetMediaContentFormIsValidEvent.SET, SetMediaContentFormIsValidCommand);
			addCommand(SetMediaFormIsValidEvent.SET, SetMediaFormIsValidCommand);
			addCommand(SetFormIsValidEvent.SET, SetFormIsValidCommand);
			
			addCommand(CheckConvertedSlideForCorrectnessEvent.CHECK, CheckConvertedSlideForCorrectnessCommand);
			addCommand(CheckForPPTOnServerEvent.CHECK, CheckForPPTOnServerCommand);
		}
		
		/**
		 * add all properties commands
		 */
		private function addPropertiesCommands():void
		{
			addCommand(LoadPropertiesEvent.LOAD, LoadPropertiesCommand);
		}
		
		/**
		 * add all user commands
		 */
		private function addUserCommands():void
		{
			addCommand(GetUserEvent.GET, GetUserCommand);
			addCommand(GetUserGroupsEvent.GET, GetUserGroupsCommand);
			addCommand(UpdateUserEvent.UPDATE, UpdateUserCommand);
			addCommand(SaveUserEvent.SAVE, SaveUserCommand);
			addCommand(DeleteUserEvent.DELETE, DeleteUserCommand);
		}
		
		/**
		 * add all feed commands
		 */
		private function addFeedCommands():void
		{
			addCommand(GetFeedEvent.GET, GetFeedCommand);
			addCommand(UpdateFeedEvent.UPDATE, UpdateFeedCommand);
			addCommand(DeleteFeedEvent.DELETE, DeleteFeedCommand);
			addCommand(GetFeedItemsEvent.GET, GetFeedItemsCommand);
			
			addCommand(UpdateFeedItemStatusEvent.UPDATE, UpdateFeedItemStatusCommand);
			addCommand(UpdateFeedItemEvent.UPDATE, UpdateFeedItemCommand);
		}
		
		/**
		 * add all player commands
		 */
		private function addPlayerCommands():void
		{
			addCommand(GetPlayerEvent.GET, GetPlayerCommand);
			addCommand(SavePlayerEvent.SAVE, SavePlayerCommand);
			addCommand(UpdatePlayerEvent.UPDATE, UpdatePlayerCommand);
			addCommand(AddPlaylistToPlayerEvent.ADD, AddPlaylistToPlayerCommand);
			addCommand(DeletePlaylistFromPlayerEvent.DELETE, DeletePlaylistFromPlayerCommand);
			addCommand(DeletePlayerEvent.DELETE, DeletePlayerCommand);
		}
		
		/**
		 * add all playlist commands
		 */
		private function addPlaylistCommands():void
		{
			addCommand(SavePlaylistEvent.SAVE, SavePlaylistCommand);
			addCommand(GetPlaylistsEvent.GET, GetPlaylistsCommand);
			addCommand(UpdatePlaylistEvent.UPDATE, UpdatePlaylistCommand);
			addCommand(GetPlaylistsForPlayerEvent.GET, GetPlaylistsForPlayerCommand);
			addCommand(DeletePlaylistEvent.DELETE, DeletePlaylistCommand);
		}
		
		/**
		 * add all media commands
		 */
		private function addMediaCommands():void
		{
			addCommand(SaveVideoEvent.SAVE, SaveVideoCommand);	
			addCommand(SaveSlideEvent.SAVE, SaveSlideCommand);
			addCommand(SaveTextEvent.SAVE, SaveTextCommand);
			addCommand(SaveImageEvent.SAVE, SaveImageCommand);
			addCommand(SaveFeedEvent.SAVE, SaveFeedCommand);
			
			addCommand(UpdateSlideEvent.UPDATE, UpdateSlideCommand);
			addCommand(UpdateTextEvent.UPDATE, UpdateTextCommand);
			addCommand(UpdateVideoEvent.UPDATE, UpdateVideoCommand);
			addCommand(UpdateImageEvent.UPDATE, UpdateImageCommand);
			
			addCommand(GetMediaEvent.GET, GetMediaCommand);
			addCommand(DeleteMediaEvent.DELETE, DeleteMediaCommand);
			addCommand(UpdateMediaEvent.UPDATE, UpdateMediaCommand);
			addCommand(SetApprovedStatusEvent.SET, SetApprovedStatusCommand);
			
			addCommand(GetUserMediaEvent.GET, GetUserMediaCommand);
			addCommand(GetExpiredMediaEvent.GET, GetExpiredMediaCommand);
		}
		
		/**
		 * add all login commands
		 */
		private function addLoginCommands():void
		{
			addCommand(LoginEvent.LOGIN, LoginCommand);
			addCommand(LogoutEvent.LOGOUT, LogoutCommand);
		}
		
	}
}